package com.yc2.Test01;

/**
 * @ClassName test02
 * @since: 2023/7/25 18:53
 * @auth: kirito
 * @description:
 **/
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class test02 {
    public static void main(String[] args) throws InterruptedException {
        // 创建一个具有五个线程的线程池
        ExecutorService threadPool = Executors.newFixedThreadPool(5);

        // 提交任务到线程池
        for (int i = 0; i < 5; i++) {
            threadPool.execute(new TimeRunnable());
            Thread.sleep(1000);
        }

        // 关闭线程池
        threadPool.shutdown();
    }

    static class TimeRunnable implements Runnable {
        @Override
        public void run() {
            while (true){
                Date d = new Date();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String fileName = sdf.format(d);
                System.out.println(Thread.currentThread().getName()+"  "+fileName);
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}